package com.dao.impl;

import com.bean.Message;
import com.bean.Student;
import com.dao.BaseDao;
import com.dao.MessageDao;
import com.utils.SqlUtils;

import java.util.List;
import java.util.Map;

public class MessageDaoImpl extends BaseDao implements MessageDao {
    String[] strings = {"StudentName"};
    @Override
    public List<Message> selectForPageItems(int begin, int pageSize, String content) {
        if (content == null) {
            content = "";
        }
        content = "%" + content + "%";
        String sql = SqlUtils.pageSql(Message.class, Student.class, strings);
        return queryForList(Message.class, sql, content, begin, pageSize);
    }

    @Override
    public Integer selectForPageTotalCount(String content) {
        if (content == null) {
            content = "";
        }
        content = "%" + content + "%";
        String sql = SqlUtils.countSql(Message.class, Student.class, strings);
        Number count = (Number) queryForSingleValue(sql, content);
        return count.intValue();
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        String sql = "delete from `message` where `id` = ?";
        return update(sql, id);
    }

    @Override
    public int insert(Message message) {
        Map.Entry<String, Object[]> entry = SqlUtils.insertSql(message, strings);
        return update(entry.getKey(), entry.getValue());
    }

    @Override
    public Message selectBy(Message message) {
        Map.Entry<String, Object[]> entry = SqlUtils.selectBy(message, Student.class, strings);
        return queryForOne(Message.class,entry.getKey(),entry.getValue());
    }

    @Override
    public int updateByPrimaryKey(Message message) {
        Map.Entry<String, Object[]> entry = SqlUtils.updateSql(message, strings);
        return update(entry.getKey(),entry.getValue());
    }
}
